/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.display {
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.display.button.AbstractButton;
	import com.googlecode.milib.vo.MLEvent;
	import com.googlecode.milib.vo.MLEventInfo;

	import flash.display.DisplayObject;

	/**
	 * @author Marek Brun
	 */
	public class MCDragController extends MCDragModel implements IMLBroadcasterListener {

		private var btn:AbstractButton;
		private var autoSetXY:Boolean;
		
		public function MCDragController(display:DisplayObject, btn:AbstractButton, autoSetXY:Boolean=true) {
			super(display);
			this.btn=btn;
			this.autoSetXY=autoSetXY;
			btn.addListener(this);
		}
		
//********************************************************************************************
//		events for MCDragModelWithButton
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case btn:
					switch(ev.event) {
						case btn.event_Press:
							start();
						break;
//						case btn.event_ReleaseAll:
//							stop();
//						break;
					}
				break;
			}
		}
		
		override public function onMouseMove(event:MLEvent):void {
			super.onMouseMove(event);
			if(autoSetXY){
				display.x=getX();
				display.y=getY();
			}
		}
		
	}
}
